解决SpringBoot项目出现Whitelabel Error Page的问题(下) 您所在的位置:网站首页 whitelabel error page怎么解决网页 解决SpringBoot项目出现Whitelabel Error Page的问题(下)

解决SpringBoot项目出现Whitelabel Error Page的问题(下)

2024-07-12 03:02| 来源: 网络整理| 查看: 265

3.解决Whitelabel Error Page的问题 # application.properties server.servlet.context-path=/restful-demo package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages="com.example") public class RestfulDemoApplication { public static void main(String[] args) { SpringApplication.run(RestfulDemoApplication.class, args); } }

@ComponentScan(basePackages="com.example"):Tells Spring to look for other components, configurations, and services in the com/example package, letting it find the controllers.

Whitelabel Error Page的问题就解决了!

当然,@ComponentScan(basePackages="com.example")不是必须的。

SpringBoot默认会扫描启动类所在的包及其子包。启动类是注解@SpringBootApplication标注的类。

出现Whitelabel Error Page问题的情况:

Controller等组件不在SpringBoot的扫描路径中。 没有在application.properties文件中指定server.servlet.context-path。

参考:

Getting Started | Building a RESTful Web Service


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有